import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {VideoListService} from "../../service/http-service/getvideolist.service";
import {ApplicantService} from "../../service/http-service/applicant.service";

/**
 * Generated class for the HistoryPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-history',
  templateUrl: 'history.html',
})
export class HistoryPage {

  sliders:{};
  currentPage: any;
  video_datas: any;
  lastPage: any;


  constructor(public navCtrl: NavController, public navParams: NavParams,
              public videoListService: VideoListService,
              public  applicationService: ApplicantService, ) {
  }


  ionViewDidLoad(){



    // this.dofresh();
    this.getHistory();


  }

  getHistory(){
    // this.currentPage="1";

    this.videoListService.getWatchedVideo().subscribe(resp=>{

      // console.log("aaaaaa")
      if (resp.data !== null && resp.code == 200) {

        // console.log(resp.data);


        this.video_datas=resp.data.list;
        this.lastPage=resp.data.isLastPage;

        // this.sliders=resp.data;
        console.log(resp.data);
        // console.log(this.video_datas[0].img);
        // console.log(this.video_datas.list[4].img);
      }else if (resp.data !== null && resp.code == 1401) {
        console.log("errrovideo");
        this.applicationService.freshTokenn();
      }
    },error2 => {
      console.log("error");
      console.log(error2);
    });

  }



  // dofresh(){
  //   this.currentPage=1;
  //
  //   this.videoListService.postVideoList(this.currentPage).subscribe(resp=>{
  //
  //     // console.log("aaaaaa")
  //     if (resp.data!==null){
  //
  //       // console.log(resp.data);
  //
  //
  //       this.video_datas=resp.data.list;
  //       this.lastPage=resp.data.isLastPage;
  //
  //       // this.sliders=resp.data;
  //       console.log(resp.data);
  //       // console.log(this.video_datas[0].img);
  //       // console.log(this.video_datas.list[4].img);
  //     }else {
  //       console.log("resp.data==null")
  //     }
  //   },error2 => {
  //     console.log("error");
  //     console.log(error2);
  //   });
  //
  // }

  new (videoId:number){

    this.navCtrl.push('ListvidoPage',{'Id':videoId});
  }


}

